home *** CD-ROM | disk | FTP | other *** search
File List | 1993-07-25 | 11.4 KB | 322 lines |
- $m29952 ! Get some memory for our application.
- '
- ' SRG Window Resource Example
- ' by Scott R. Garrigus
- ' SRG Software July 25, 1993
- '
- ' This code can be freely distributed as long it is done intact. It can
- ' be used freely in whole or in part in your own programs. FREEWARE from
- ' SRG Software.
- '
- ' This application runs both as an ACC and as a PRG.
- ' It is an example showing how to use a resource dialog in a window.
- '
- ap_id&=APPL_INIT() ! Get an ID number for our ACC/PRG from AES.
- '
- IF ap_id&<>0 ! If we're run as an ACC...
- '
- IF RSRC_LOAD("srgexmpl.rsc")=0 ! If resource can't be found...
- '
- resource!=FALSE ! Set resource flag to false.
- '
- DIM message_buffer&(7) ! Set up a buffer for AES messages.
- mesg_adr%=V:message_buffer&(0) ! Get the address of the buffer.
- '
- ' Set up the variables needed when receiving messages.
- '
- ABSOLUTE mesg_type&,mesg_adr% ! Holds the type of message received.
- ABSOLUTE x&,mesg_adr%+8 ! x coordinate of redraw area or window.
- ABSOLUTE y&,mesg_adr%+10 ! y coordinate of redraw area or window.
- ABSOLUTE w&,mesg_adr%+12 ! width of redraw area or window.
- ABSOLUTE h&,mesg_adr%+14 ! height of redraw area or window.
- ABSOLUTE acc_id&,mesg_adr%+8 ! Holds the ID of the ACC activated by user.
- '
- ' Put our ACC name in the Desk menu and save the number of the
- ' menu slot it is in.
- '
- me_id&=MENU_REGISTER(ap_id&," SRG RSC Example ")
- '
- ELSE ! If our resource was found...
- resource!=TRUE ! Set our resource flag to true.
- exit!=TRUE ! Set our exit flag to true, because we are just
- ' initializing right now. The ACC is not open yet.
- '
- @init ! Do the rest of our initialization. Both ACC and PRG.
- '
- ' The following variables are only needed by the ACC.
- '
- ' Put our ACC name in the Desk menu and save the number of the
- ' menu slot it is in.
- '
- me_id&=MENU_REGISTER(ap_id&," SRG RSC Example ")
- '
- ENDIF
- '
- ' Now enter the main ACC loop and loop forever, since ACC's
- ' are never exited.
- '
- DO
- @do_events !Get event messages from AES.
- LOOP
- '
- ELSE ! If we're run as a PRG...
- '
- IF RSRC_LOAD("srgexmpl.rsc")=0 ! If our resource can't be found...
- '
- ~FORM_ALERT(1,"[1][Resource not found.][Bye]") ! Alert the user,
- '
- ~APPL_EXIT() ! and exit the program.
- QUIT (0)
- '
- ELSE ! If our resource was found...
- '
- resource!=TRUE ! Set our resource flag to true.
- '
- ENDIF
- '
- @init ! Do the rest of our initialization. Both ACC and PRG.
- '
- ' The following variables are those needed for the PRG only.
- '
- ' Set up variables for our menu bar, which was created with the RCS.
- '
- LET menu&=2 ! Menu object number.
- LET deskmenu&=6 ! Desk object numer.
- '
- ' Set up variables to hold the menu title and menu item numbers
- ' which are selected by the user when an AES menu message occurs.
- '
- ABSOLUTE m_title&,mesg_adr%+6 ! Holds the menu title object number.
- ABSOLUTE m_item&,mesg_adr%+8 ! Holds the menu item object number.
- '
- ~RSRC_GADDR(0,menu&,menu_adr%) ! Get the address of our menu, which
- ' was loaded in with the RCS file.
- '
- ~MENU_BAR(menu_adr%,1) ! Display our menu bar on the screen.
- '
- @do_window ! Set up and open our window.
- '
- exit!=FALSE ! Set our exit flag to false since we are not exiting yet.
- '
- ~GRAF_MOUSE(0,pattern_adr%) ! Set the mouse to an arrow.
- '
- ' Now loop until our exit flag is true.
- '
- REPEAT
- @do_events ! Get event messages from AES.
- UNTIL exit!
- '
- ENDIF
- '
- ~MENU_BAR(menu_adr%,0) ! Turn our menu bar off.
- '
- ~RSRC_FREE() ! Free up the memory our resource file took.
- '
- ~APPL_EXIT() ! Exit our program.
- QUIT (0)
- '
- '
- '
- PROCEDURE init
- '
- ' This is where we initialize things pertaining to both the ACC and
- ' the PRG.
- '
- ' Variables from our resource file.
- '
- LET maindial&=0 ! Main dialog tree.
- LET infobutn&=1 ! Info button in main dialog.
- '
- LET crdtdial&=1 ! Credit dialog tree.
- LET crdtbutn&=9 ! Credit button in credit dialog.
- '
- DIM message_buffer&(7) ! Set up a buffer for AES messages.
- mesg_adr%=V:message_buffer&(0) ! Get the address of the buffer.
- '
- ' Set up the varibles needed when receiving messages.
- '
- ABSOLUTE mesg_type&,mesg_adr% ! Holds the type of message received.
- ABSOLUTE x&,mesg_adr%+8 ! x coordinate of redraw area or window.
- ABSOLUTE y&,mesg_adr%+10 ! y coordinate of redraw area or window.
- ABSOLUTE w&,mesg_adr%+12 ! width of redraw area or window.
- ABSOLUTE h&,mesg_adr%+14 ! height of redraw area or window.
- ABSOLUTE acc_id&,mesg_adr%+8 ! Holds the ID of the ACC activated by user.
- ABSOLUTE window_selected&,mesg_adr%+6 ! Holds the handle of the window
- ' that was selected by the user.
- '
- ' Get the addresses of all the dialogs used in the ACC/PRG.
- '
- ~RSRC_GADDR(0,maindial&,maindial_adr%)
- ~RSRC_GADDR(0,crdtdial&,crdtdial_adr%)
- '
- ' Get the starting coordinates (center of screen) of the dialogs.
- '
- ~FORM_CENTER(maindial_adr%,mainx&,mainy&,mainw&,mainh&)
- ~FORM_CENTER(crdtdial_adr%,crdtx&,crdty&,crdtw&,crdth&)
- '
- ' Compute the total size we need our window to be by using
- ' the size of the MIDI dialog, which will fit inside the
- ' window work area. Our window will have a title bar with
- ' name, a close box, and a movement bar. (eg. 1+2+8)
- '
- ~WIND_CALC(0,1+2+8,mainx&,mainy&,mainw&,mainh&,windx&,windy&,windw&,windh&)
- '
- RETURN
- '
- '
- PROCEDURE do_window
- '
- ' Create our main window to the appropriate size as to fit our
- ' resource menu inside the work area.
- '
- handle&=WIND_CREATE(1+2+8,windx&,windy&,windw&,windh&)
- '
- ' Set up a title for our window
- '
- title$=" SRG RSC Window Example " ! Be sure title has even # of chars.
- adr_title%=V:title$ ! Get the address of the title.
- '
- ' Assign the title to our window
- '
- ~WIND_SET(handle&,2,CARD(SWAP(adr_title%)),CARD(adr_title%),0,0)
- '
- ' Open our window and find the coordinates of it's work area.
- '
- ~WIND_OPEN(handle&,windx&,windy&,windw&,windh&)
- ~WIND_GET(handle&,4,wx&,wy&,ww&,wh&)
- '
- ' Set the coordinates of our resource menu to that of the
- ' window work area and then a redraw will display it inside the window.
- OB_X(maindial_adr%,0)=wx&
- OB_Y(maindial_adr%,0)=wy&
- '
- RETURN
- '
- '
- PROCEDURE do_events
- '
- ' Get both message and left mouse button events.
- '
- evnt%=EVNT_MULTI(2+16,1,1,1,0,0,0,0,0,0,0,0,0,0,mesg_adr%,0,mcur_x%,mcur_y%,button%,dummy%,dummy%,dummy%)
- IF resource! AND exit!=FALSE ! If resource found and not exited...
- IF BTST(evnt%,1) ! If it's a button event...
- @process_maindial ! Find out what was pressed and process it.
- ENDIF
- ENDIF
- IF BTST(evnt%,4) ! If it's a message event...
- @process_message ! Find out what type of message and process it.
- ENDIF
- RETURN
- '
- '
- PROCEDURE process_message
- '
- SELECT mesg_type& ! Get the type of message received.
- '
- CASE 10 ! If it's a menu message...
- IF ap_id&=0 ! and if we're run as a PRG...
- IF m_item&=deskmenu& ! If the desk menu is selected...
- @do_credits ! display our credits dialog.
- ~MENU_TNORMAL(menu_adr%,m_title&,1) ! Unselect the menu title.
- ENDIF
- ENDIF
- '
- CASE 20 ! If it's a redraw message...
- IF window_selected&=handle& ! and it's our window...
- ~WIND_UPDATE(1) ! Freeze all AES operations for a screen redraw.
- ~WIND_GET(handle&,11,rx&,ry&,rw&,rh&) ! Get the first rectangle to
- ' be redrawn.
- ~WIND_GET(handle&,4,ax&,ay&,aw&,ah&) ! Get the size of the window
- ' work area.
- REPEAT ! Start redrawing each rectangle...
- ' If our work area contains the rectangle...
- IF RC_INTERSECT(ax&,ay&,aw&,ah&,rx&,ry&,rw&,rh&)
- CLIP rx&,ry&,rw&,rh& OFFSET ax&,ay& ! Clip the area to draw.
- ~OBJC_DRAW(maindial_adr%,0,1,rx&,ry&,rw&,rh&) ! Draw menu.
- CLIP 0,0,WORK_OUT(0),WORK_OUT(1) ! Clip whole screen.
- ENDIF
- '
- ~WIND_GET(handle&,12,rx&,ry&,rw&,rh&) ! Get next rectangle to draw.
- UNTIL rw&=0 AND rh&=0 ! All rectangles are drawn.
- ~WIND_UPDATE(0) ! Resume AES operations. Redraw is done.
- ENDIF
- '
- CASE 21 ! If it's a window top message...
- IF window_selected&=handle& ! and if it's our window...
- ~WIND_SET(handle&,10,dummy%,dummy%,dummy%,dummy%) ! Top our window.
- ENDIF
- '
- CASE 22 ! If it's a window close message...
- IF window_selected&=handle& ! and if it's our window...
- ~WIND_CLOSE(handle&) ! Close our window,
- ~WIND_DELETE(handle&) ! and delete it so AES can use it for something
- ' else.
- exit!=TRUE ! Also set our exit flag to true.
- ENDIF
- '
- CASE 28 ! If it's a window move message...
- IF window_selected&=handle& ! and if it's our window...
- ~WIND_SET(handle&,5,x&,y&,w&,h&) ! Move our window.
- windx&=x& ! Save it's x and y coordinates so that if closed
- windy&=y& ! and then reopened, it will be in the same place.
- ~WIND_GET(handle&,4,wx&,wy&,ww&,wh&) ! Where's our work area...
- OB_X(maindial_adr%,0)=wx& ! Set our resource menu coordinates
- OB_Y(maindial_adr%,0)=wy& ! to the place as our work area,
- ENDIF
- '
- CASE 40 ! If it's an ACC open message...
- IF acc_id&=me_id& ! and it's our ACC...
- IF resource! ! and our resource was found...
- IF exit! ! and we are exited...
- exit!=FALSE ! Set our exit flag to false because we're now open.
- ~GRAF_MOUSE(0,pattern_adr%) ! Change our mouse to an arrow.
- @do_window ! Open our ACC window.
- ELSE ! If we're already open...
- ~WIND_SET(handle&,10,dummy%,dummy%,dummy%,dummy%) ! Top our window.
- ENDIF
- ELSE ! If our resource wasn't found...
- ~FORM_ALERT(1,"[1][Couldn't find resource.|Disabled temporarily.][OK]")
- ENDIF
- ENDIF
- '
- CASE 41 ! If it's an ACC close message...
- ' and we haven't already closed our window, pretend it's closed
- ' because GEM is going to close it for us. Presumably, the program
- ' that was running when we were opened has finished.
- '
- exit!=TRUE
- '
- ENDSELECT
- RETURN
- '
- '
- PROCEDURE process_maindial ! find and process the button message.
- '
- ' Find out what button the mouse was over when the
- ' left button was pressed.
- object%=OBJC_FIND(maindial_adr%,0,1,mcur_x%,mcur_y%)
- '
- SELECT object%
- CASE infobutn& ! If the info. button is selected...
- @do_credits ! display program credits, etc.
- ENDSELECT
- RETURN
- '
- '
- PROCEDURE do_credits
- OB_STATE(maindial_adr%,infobutn&)=33
- ~OBJC_DRAW(maindial_adr%,infobutn&,0,windx&,windy&,windw&,windh&)
- ~EVNT_BUTTON(1,1,0)
- OB_STATE(maindial_adr%,infobutn&)=32
- ~OBJC_DRAW(maindial_adr%,infobutn&,0,windx&,windy&,windw&,windh&)
- ~FORM_DIAL(0,0,0,0,0,crdtx&,crdty&,crdtw&,crdth&)
- ~OBJC_DRAW(crdtdial_adr%,0,1,crdtx&,crdty&,crdtw&,crdth&)
- ~FORM_DO(crdtdial_adr%,0)
- OB_STATE(crdtdial_adr%,crdtbutn&)=0
- ~OBJC_DRAW(crdtdial_adr%,crdtbutn&,0,crdtx&,crdty&,crdtw&,crdth&)
- ~FORM_DIAL(3,0,0,0,0,crdtx&,crdty&,crdtw&,crdth&)
- RETURN
- '
- '
- ' ** The End **
-